<?php
    // include "config.php";

    //连接数据库
    $conn = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME);
    //查询sql语句
    $sql = "select * from comments c
    ORDER BY c.created DESC
    LIMIT 6";
    //执行sql语句
    $results = mysqli_query($conn,$sql);
    $resultArrs = [];
    while($row = mysqli_fetch_assoc($results)){
        $resultArrs[] = $row;
    }
    // print_r($resultArrs);
?>
<style>
    .discuz .cs{
        height:20px;
        overflow:hidden;
    }
</style>
<div class="aside">
    <div class="widgets">
    <h4>搜索</h4>
    <div class="body search">
        <form>
        <input type="text" class="keys" placeholder="输入关键字">
        <input type="submit" class="btn" value="搜索">
        </form>
    </div>
    </div>
    <div class="widgets">
    <h4>随机推荐</h4>
    <ul class="body random">
        <li>
        <a href="javascript:;">
            <p class="title">废灯泡的14种玩法 妹子见了都会心动</p>
            <p class="reading">阅读(819)</p>
            <div class="pic">
            <img src="static/uploads/widget_1.jpg" alt="">
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <p class="title">可爱卡通造型 iPhone 6防水手机套</p>
            <p class="reading">阅读(819)</p>
            <div class="pic">
            <img src="static/uploads/widget_2.jpg" alt="">
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <p class="title">变废为宝！将手机旧电池变为充电宝的Better</p>
            <p class="reading">阅读(819)</p>
            <div class="pic">
            <img src="static/uploads/widget_3.jpg" alt="">
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <p class="title">老外偷拍桂林芦笛岩洞 美如“地下彩虹”</p>
            <p class="reading">阅读(819)</p>
            <div class="pic">
            <img src="static/uploads/widget_4.jpg" alt="">
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <p class="title">doge神烦狗打底南瓜裤 就是如此魔性</p>
            <p class="reading">阅读(819)</p>
            <div class="pic">
            <img src="static/uploads/widget_5.jpg" alt="">
            </div>
        </a>
        </li>
    </ul>
    </div>
    <div class="widgets">
    <h4>最新评论</h4>
    <ul class="body discuz">
        <?php foreach($resultArrs as $value) :?>
            <li>
                <a href="javascript:;">
                    <div class="avatar">
                        <img src="static/uploads/avatar_1.jpg" alt="">
                    </div>
                    <div class="txt">
                        <p>
                            <span><?php echo $value['author'] ?></span>
                            <?php
                                $date1 = strtotime(date("Y-m-d"));
                                $date2 = strtotime($value['created']);
                                $date3 = $date1-$date2;
                                $date4 = date("Y-m");
                                echo $date4;

                                
                            ?>
                            个月前<?php echo $value['created']?>
                            说:
                        </p>
                        <p class="cs"><?php echo $value['content']; ?></p>
                    </div>
                </a>
            </li>
        <?php endforeach ?>
        <!-- <li>
        <a href="javascript:;">
            <div class="avatar">
            <img src="static/uploads/avatar_1.jpg" alt="">
            </div>
            <div class="txt">
            <p>
                <span>鲜活</span>9个月前(08-14)说:
            </p>
            <p>挺会玩的</p>
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <div class="avatar">
            <img src="static/uploads/avatar_1.jpg" alt="">
            </div>
            <div class="txt">
            <p>
                <span>鲜活</span>9个月前(08-14)说:
            </p>
            <p>挺会玩的</p>
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <div class="avatar">
            <img src="static/uploads/avatar_2.jpg" alt="">
            </div>
            <div class="txt">
            <p>
                <span>鲜活</span>9个月前(08-14)说:
            </p>
            <p>挺会玩的</p>
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <div class="avatar">
            <img src="static/uploads/avatar_1.jpg" alt="">
            </div>
            <div class="txt">
            <p>
                <span>鲜活</span>9个月前(08-14)说:
            </p>
            <p>挺会玩的</p>
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <div class="avatar">
            <img src="static/uploads/avatar_2.jpg" alt="">
            </div>
            <div class="txt">
            <p>
                <span>鲜活</span>9个月前(08-14)说:
            </p>
            <p>挺会玩的</p>
            </div>
        </a>
        </li>
        <li>
        <a href="javascript:;">
            <div class="avatar">
            <img src="static/uploads/avatar_1.jpg" alt="">
            </div>
            <div class="txt">
            <p>
                <span>鲜活</span>9个月前(08-14)说:
            </p>
            <p>挺会玩的</p>
            </div>
        </a>
        </li> -->
    </ul>
    </div>
</div>